<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>角色更新</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/lib/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/css/public.css}" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">名称</label>
        <div class="layui-input-block">
            <input type="hidden" name="roleId" th:value="${roleInfo.roleId}">
            <input type="text" name="name" lay-verify="required|name" lay-reqtext="请输入角色名称" placeholder="请输入角色名称" th:value="${roleInfo.name}" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">标识</label>
        <div class="layui-input-block">
            <input type="text" name="sign" lay-verify="required|letter" lay-reqtext="请输入角色标识" placeholder="请输入角色标识" th:value="${roleInfo.sign}" class="layui-input">
            <tip>角色标识作为唯一标识，请输入全英文</tip>
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">描述</label>
        <div class="layui-input-block">
            <textarea name="descript" class="layui-textarea" placeholder="请输入描述信息" th:text="${roleInfo.descript}"></textarea>
        </div>
    </div>

    <!-- 右侧悬浮按钮 -->
    <div class="right-bottom-btn">
        <button class="layui-btn" lay-submit lay-filter="saveBtn"><i
                class="layui-icon layui-icon-ok"></i>确认
        </button>
        <button class="layui-btn" lay-filter="cancleBtn"><i
                class="layui-icon layui-icon-close"></i>取消
        </button>
    </div>

</div>
<script th:src="@{/lib/jquery-3.4.1/jquery-3.4.1.min.js}" charset="utf-8"></script>
<script th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
<script th:src="@{/lib/coco-message/coco-message.js}" charset="utf-8"></script>
<script th:src="@{/js/lay-config.js}" charset="utf-8"></script>
<script th:inline="javascript" type="text/javascript">
    AjaxUtil.ctx = /*[[@{/}]]*/'';
    layui.use(['form', 'layer'], function () {
        var form = layui.form,
            layer = layui.layer;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var index = layer.alert('确认提交吗？', function () {
                var loading = layer.load(0, {shade: 0.1});
                AjaxUtil.post({
                    url: AjaxUtil.ctx + "roleinfo/doUpdate",
                    data: data.field,
                    success: function (res) {
                        if (res.code === 0) {
                            layer.close(index);
                            layer.close(loading);
                            Message.success(1500, res.message, function () {
                                // 重载表格
                                var iframeIndex = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(iframeIndex);
                            });
                        } else {
                            layer.close(loading);
                            Message.error(res.message, 1000);
                        }
                    },
                    error: function (error) {
                    }
                });
            });
            return false;
        });

        form.verify({
            name: function(value, item) { //value：表单的值、item：表单的DOM对象
                if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
                    return '角色名不能有特殊字符';
                }
                if(/(^\_)|(\__)|(\_+$)/.test(value)){
                    return '角色名首尾不能出现下划线\'_\'';
                }
                if(/^\d+\d+\d$/.test(value)){
                    return '角色名不能全为数字';
                }
            },
            letter: function (value, item) {
                if (!new RegExp("^[a-zA-Z]+$").test(value)) {
                    return '角色标识作为唯一标识，请输入全英文';
                }
            }
        });

        // 监听取消按钮
        $("button[lay-filter='cancleBtn']").click(function(){
            var iframeIndex = parent.layer.getFrameIndex(window.name);
            parent.layer.close(iframeIndex);
        });
    });
</script>
</body>
</html>